﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Server_NhaSach.DataAccess.LogicLayer;
using Server_NhaSach.DataTransferObject;
using System.Data;

namespace Server_NhaSach.BusinessLayer
{
    public class MatHangBlo
    {
        #region "Khai báo các biến"
        private MatHangDAO da;
        private MatHangDTO _mathang;
        private string _error;
        #endregion

        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
        }
        public MatHangDTO MatHang
        {
            get { return _mathang; }
            set { _mathang = value; }
        }
        #endregion

        #region "Khai báo các Method"
        public MatHangBlo()
        {
            da = new MatHangDAO();
        }
        public bool InsertMatHang(string mamh, string maloai, string tenmh, double dgn, double dgs, double dgl, float km, string nhasx, string tg, string namsx, string dausach, string dvt, int slDauKy, int slHienCo, byte[] hinh)
        {
            _mathang = new MatHangDTO(mamh, maloai, tenmh, dgn, dgs, dgl,km, nhasx, tg, namsx, dausach,dvt,slDauKy,slHienCo,hinh);
            if (!da.InsertMatHang(MatHang))
            {
                _error = da.Error;
                return false;
            }
            return true;
        }
        public bool UpdateMatHang(string mamh, string maloai, string tenmh, double dgn, double dgs, double dgl, float km, string nhasx, string tg, string namsx, string dausach, string dvt, int slDauKy, int slHienCo, byte[] hinh)
        {
            _mathang = new MatHangDTO(mamh, maloai, tenmh, dgn, dgs, dgl, km, nhasx, tg, namsx, dausach, dvt, slDauKy, slHienCo, hinh);
            if (!da.UpdateMatHang(MatHang))
            {
                _error = da.Error;
                return false;
            }
            return true;
        }
        public bool DeleteMatHang(string MaMH)
        {
            if (!da.DeleteMatHang(MaMH))
            {
                _error = da.Error;
                return false;
            }
            return true;
        }
        public DataSet LayDS_MatHang()
        {
            DataSet ds = new DataSet();
            ds = da.LayDS_MatHang();
            return ds;
        }
        #endregion        
    }
}